home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: Basic Question on SWITCH
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DM5qor.9G1@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <4e8p6m$n8q@ns.RezoNet.NET> <TANMOY.96Jan26162346@qcd.lanl.gov> <4ehfuj$166g@ns.RezoNet.NET>
- Date: Fri, 2 Feb 1996 16:48:26 GMT
-
- In article <4ehfuj$166g@ns.RezoNet.NET>, ray@ultimate-tech.com
- (Ray Dunn) writes:
- >[Tanmoy Bhattacharya and/or Ari Lukumies had written:]
- >> A special case for digits:
- >> if ((unsigned)(a-'0')<10)
- >> /* It _is_ a digit, do something */
- >> But then what is wrong with isdigit?
- >
- > Indeed. In the general case there is no guarantee that all the digits
- > are consecutive as they are in ASCII, so the use of isdigit is the only
- > portable way to go...
-
- Actually, it turns out that there *is* a guarantee that the
- digits are consecutive, and it's in about the highest authority
- possible: the ANSI/ISO Standard (section 2.2.1 in the old ANSI
- version). It's true that you rarely need to make use of this
- guarantee when testing for digits, because isdigit() is usually a
- better choice, but it makes it *much* easier to write anything
- that has to convert number strings to numbers (a la atoi),
- because there isn't a standard ctod() or digit_weight() function.
-
- (What's true is that the *letters* aren't guaranteed to be
- consecutive, as they aren't in EBCDIC. So be careful when you're
- writing strtol, although for A-F I think you're safe in EBCDIC,
- too.)
-
- Steve Summit
- scs@eskimo.com
-